function result = SaveBehavior_GAPS(schedule,experiment,RC)
% result = SaveBehavior_GAPS(schedule,experiment,RC)
%
% Save session data for Gap detection paradigm.
% 
% RC = "request condition" and is an optional boolean value
% 
% DJS (c) 2010


result = false;

if ~isempty(whos('RC')) && RC
    opts.WindowStyle = 'modal';
    schedule.condition = char(inputdlg('Enter this session''s condition:', ...
        'Enter Condition',1,{''},opts));
end

df = cd;
if isfield(experiment,'resultsdir')
    df = experiment.resultsdir;
end

[filename,pathname,filterindex] = uiputfile( ...
    {'*.mat;','MAT-files (*.mat)'}, ...
    'Save as',df); %#ok<NASGU>

if isequal(filename,0) || isequal(pathname,0), return;  end

fn = fullfile(pathname,filename);

schedule.experiment = experiment;

save(fn,'schedule');

if exist(fn,'file')
    fprintf('Box #%d saved as: %s\n',schedule.BoxID,fn)
    result = true;
else
    errordlg('An error was encountered while saving data!','Save Data','modal');
end


